﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Net;

using EHTWebsite.Code;
using EHTWebsiteProject.Code.BLL;
using System.Resources;
using System.Threading;
using System.Globalization;
using EHTWebsiteProject.Code.Entity;

namespace EHTWebsiteProject
{
    /// <summary>
    /// chiennv
    /// page: san pham chi tiet
    /// </summary>
    public partial class ProductDetails : System.Web.UI.Page
    {
        private Int32 SanPhamID = HangSo.DEFAULT_ID;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SanPhamID = Int32.Parse(Request.QueryString["SanPhamID"].ToString());
                Session["SanPhamID"] = SanPhamID.ToString();
            }
            catch (Exception ex)
            {
                SanPhamID = HangSo.DEFAULT_ID;
            }

            if (!Page.IsPostBack)
            {
                LoadSanPham(SanPhamID);
                ltrVote.Text = HelpMethod.CreateAllButtonShared("http://re-konsult.com/Produkt-" + SanPhamID + "-detaljer.html", SanPhamProvider.GetSanPhamBySanPhamID(SanPhamID).TenSanPhamVN.ToString());
            }
        }

        public void LoadSanPham(Int32 SanPhamID)
        {
            SanPham theProduct = SanPhamProvider.GetSanPhamBySanPhamID(SanPhamID);
            if (theProduct != null)
            {
                lbCategoryName.Text = DanhMucSanPhamProvider.GetDanhMucSanPhamByDanhMucID(theProduct.DanhMucID).TenDanhMucVN;

                lblPricePerUnit.Text = theProduct.PricePerUnit.ToString();
                lbName.Text = theProduct.TenSanPhamVN;
                lbPrice.Text = theProduct.DonGia.ToString();
                lbQuantityPerUnit.Text = theProduct.QuantityPerUnit.ToString();
                ImgProduct.ImageUrl = theProduct.HinhAnhUrl.ToString();
                lbDiscount.Text = theProduct.GiamGia.ToString();
                this.lbUnitInStock.Text = theProduct.UnitsInStock.ToString();
                this.lbDescription.Text = theProduct.MoTaVN.ToString();
            }
        }

        protected void ImgBuy_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                int quantity = Int32.Parse(txtquantity.Text.ToString());
                txtquantity.Text = quantity.ToString();
                if (quantity == 0)
                {
                    ltrMessage.Text = "Vennligst skriv inn mengde";
                    Response.Redirect("Produkt-" + Session["SanPhamID"].ToString() + "-detaljer.html");
                }
                else
                {

                    ShoppingCart.Instance.AddItem(Int32.Parse(SanPhamID.ToString()), quantity); ;
                    Response.Redirect("ViewCart.aspx");
                }

            }
            catch (Exception ex)
            {
                ltrMessage.Text = "Erorr: Antall er ikke numberic";
            }


        }
    }
}